﻿/* 
 * Since 2008 - 2012
 */

package com.hh.bss.customer.service.impl;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;

import com.hh.bss.base.*;
import com.hh.bss.common.page.*;
import com.hh.bss.common.page.impl.*;
import com.hh.bss.customer.dao.*;
import com.hh.bss.customer.entity.*;
import com.hh.bss.customer.service.*;
import com.hh.bss.customer.vo.query.*;
import com.hh.bss.util.*;




@Service
@Transactional
public class CompanyDeptTitleServiceImpl extends BaseBusinessService<CompanyDeptTitle,java.lang.Integer>  implements CompanyDeptTitleService<CompanyDeptTitle,java.lang.Integer>{

	private CompanyDeptTitleDao companyDeptTitleDao;
	/**增加setXXXX()方法,spring就可以通过autowire自动设置对象属性,请注意大小写*/
	public void setCompanyDeptTitleDaoImpl(CompanyDeptTitleDao dao) {
		this.companyDeptTitleDao = dao;
	}
	public EntityDao getEntityDao() {
		return this.companyDeptTitleDao;
	}
	
	@Transactional(readOnly=true)
	public Page findPage(CompanyDeptTitleQuery query) {
		return companyDeptTitleDao.findPage(query);
	}

	public List findByCompanyDept(Integer companyId, Integer deptId) {
		// TODO Auto-generated method stub
		Object[] os={companyId,deptId};
		List l=companyDeptTitleDao.getHibernateTemplate().find("from CompanyDeptTitle t where t.companyId=? and t.deptId=?",os);
		return l;
	}
	public void deleteCompanyDeptTitles(String ids) {
		String[] idarray = ids.split(",");

		//检查是否有无法删除的,有子岗位或人选
		for (int i = 0; i < idarray.length; i++)
		{

			java.lang.Integer id = new java.lang.Integer((String)idarray[i]);
			Object[] os={id};
			List l=companyDeptTitleDao.getHibernateTemplate().find("from CompanyDeptTitle t where t.parentId=?",os);
			if(l!=null&&l.size()>0) throw new RuntimeException("删除失败，存在子岗位");
			
			l=companyDeptTitleDao.getHibernateTemplate().find("from SearchProjectCv t where t.titleId=?",os);
			if(l!=null&&l.size()>0) throw new RuntimeException("删除失败，岗位下面存在人选");
		}

		
		for (int i = 0; i < idarray.length; i++)
		{

			java.lang.Integer id = new java.lang.Integer((String)idarray[i]);
			companyDeptTitleDao.deleteById(id);
		}
		// TODO Auto-generated method stub
		
	}
	
}
